#include <bits/stdc++.h>
using namespace std;
const int N = 10;

string a, b;

unordered_map<string, int> dist;
queue<string> q;

int n;
string x[N], y[N];

int bfs()
{
	q.push(a);
	dist[a] = 0;

	while(q.size())
	{
		string f = q.front(); q.pop();
		if(dist[f] > 10) return -1;
		for(int i = 0;i < n;i ++)
		{
			int pos = 0;
			while(f.find(x[i], pos) != std::string::npos)
			{
				pos = f.find(x[i], pos);
				string tmp = f.substr(0, pos) + y[i] + f.substr(pos + x[i].size());
				// cout << pos << " " << tmp << endl;
				pos ++;
				if(dist.count(tmp)) continue;
				dist[tmp] = dist[f] + 1;
				q.push(tmp);
				if(tmp == b) return dist[tmp];
			}
		}
	}
	return -1;
}

int main()
{
	cin >> a >> b;
	while(cin >> x[n] >> y[n]) n ++;
	int ans = bfs();
	if(ans == -1) cout << "NO ANSWER!" << endl;
	else cout << ans << endl;
	return 0;
}